package controller

import (
	"codeless/config"
	models "codeless/model"
	"github.com/gin-gonic/gin"
)

func (c *CrudController) UI(ctx *gin.Context) {
	code := ctx.Query("view")
	engine := models.NewUIEngine(code)
	server := config.GetAppConfig().Server
	cfg, cfgOk := models.LoadUIFile(engine.Name, server.Prod())
	if !cfgOk {
		ctx.String(401, "参数非法，权限不存在")
		return
	}
	/*if engine.Process == "add" {
		fieldList := make([]models.FormFieldVo, 0)
		for k, v := range cfg.Add[engine.Node].Columns {
			fieldList = append(fieldList, models.FormFieldVo{
				EnName:   k,
				Required: strings.Contains(v.Rule, "required"),
				CrudField: models.CrudField{
					ZhName: v.ZhName,
					Dom:    v.Dom,
					Rule:   v.Rule,
				},
			})
		}
		ctx.HTML(200, "crud/add.html", gin.H{
			"code":      code,
			"fieldList": fieldList,
			"title":     "crud",
		})
	}*/
	if engine.Process == "page" {
		ctx.HTML(200, "crud/page.html", gin.H{
			"list": cfg.List,
		})
	}

}
